package day_06;

import java.util.Arrays;

/**
 * @ClassName ShellSort1
 * @Description TODO
 * @Author hp
 * @Date 2021/6/9 13:54
 * @Version 1.0
 **/
public class ShellSort1 {
    public static void main(String[] args) {
        int []arr ={1,4,2,7,9,8,3,6};

       /* for (int gap = arr.length/2 ; gap > 0 ; gap/=2) {
            for (int i = gap; i < arr.length; i++) {
                    int j = i;
                    while (j-gap>=0&&arr[j]<arr[j-gap]){
                        arr[j] = arr[j]^arr[j-gap];
                        arr[j-gap]=arr[j]^arr[j-gap];
                        arr[j]=arr[j]^arr[j-gap];
                        j-=gap;
                    }

            }
        }
        System.out.println(Arrays.toString(arr));*/

        for (int gap = arr.length/2; gap > 0 ; gap/=2) {
            for(int i = gap;i<arr.length;i++){
                int j = i;
                while (j-gap>=0&&arr[j]<arr[j-gap]){
                    arr[j] = arr[j]^arr[j-gap];
                    arr[j-gap]=arr[j]^arr[j-gap];
                    arr[j]=arr[j]^arr[j-gap];
                    j-=gap;
                }
            }

        }
        System.out.println(Arrays.toString(arr));
    }

}
